package com.mycompany.lctwitter.action.message;

import javax.annotation.Resource;

import org.apache.struts2.convention.annotation.Result;
import org.apache.struts2.convention.annotation.Results;

import com.mycompany.lctwitter.action.AbstractAction;
import com.mycompany.lctwitter.biz.model.UserModel;
import com.mycompany.lctwitter.persist.service.MessageService;

@Results( { @Result(name = AbstractAction.SUCCESS, type = "redirect", location = "/message/list") })
public class SendAction extends AbstractAction {

    private static final long serialVersionUID = 6455671825789442815L;

    @Resource
    private MessageService messageService;

    private String message;

    public void setMessage(String message) {
        this.message = message;
    }

    @Override
    public String execute() {
        UserModel user = (UserModel) session.get(LOGINED_USER);
        messageService.addMessage(user.getUserId(), message, user.getLocation().getId());
        return SUCCESS;
    }
}
